package za.org.jcicada.genss.sensor.impl;

import java.net.URISyntaxException;
import java.util.Observable;

import za.org.jcicada.genss.sensor.ISensorValue;
import za.org.jcicada.genss.sensor.SensorURN;

/**
 * Sensor that fires directly whenever the sensor.setValue method is called
 * with a non-null value.
 * @author rcrida
 */
public class StrategyAuto extends StrategyBase {

	private static final long serialVersionUID = 1L;

	/**
     * Construct auto strategy.
     * @param sensorURN the sensor URI
     */
    public StrategyAuto(SensorURN sensorURN) {
        super(sensorURN);
    }
    
    /**
     * Construct strategy from string array
     * @param args created by toStringArray
     * @throws URISyntaxException
     */
    public StrategyAuto(String[] args) throws URISyntaxException {
        this(new SensorURN(args[0]));
    }
    
    /**
     * If the value is not null then fire a sample.
     * @param o the sensor that is being observed
     * @param arg ignored
     */
    @Override
    protected void updateValue(Observable o, ISensorValue value) {
        notifySample(value);
    }

    public String[] toStringArray() {
        return new String[]{getSensorURN().toString()};
    }

}
